﻿Public Class FrmBuscarClientes
    Dim combo As New combo
    Dim acceso As New acceso_a_datos
    Dim frmCliente As FrmABMCliente
    Public Sub New(ByRef frmCliente As FrmABMCliente)
        InitializeComponent()
        Me.frmCliente = frmCliente
    End Sub
    Private Sub cmbCategoria_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCategoria.SelectedIndexChanged
        Select Case cmbCategoria.SelectedIndex
            Case 0
                Me.lblTextoABuscar.Text = "Ingrese el número de documento que desea buscar"
                Me.cmbFiltro.Enabled = True
                Me.combo.cadena_conexion = acceso._CadenaConexion
                Me.combo.cargar(Me.cmbFiltro, "TipoDNI")
                Me.txtTextoABuscar.Visible = False
                Me.mtxtNroDocumento.Visible = True
            Case 1
                Me.lblTextoABuscar.Text = "Ingrese el apellido que desea buscar"
                Me.txtTextoABuscar.Enabled = True
                Me.cmbFiltro.Enabled = False
                btnBuscar.Enabled = True
                Me.txtTextoABuscar.Visible = True
                Me.mtxtNroDocumento.Visible = False
        End Select
    End Sub

    Private Sub cmbFiltro_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbFiltro.SelectedIndexChanged
        txtTextoABuscar.Enabled = True
        btnBuscar.Enabled = True
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        acceso._tabla = "Cliente"
        Dim consulta As String = "SELECT t.siglas as 'Tipo de Documento', c.nroDNI as 'Número de Documento', c.apellidos as 'Apellidos', c.nombres as 'Nombres',c.calle as 'Calle', c.Nro as 'Número', c.Piso as 'Piso', c.Departamento as 'Dpto',c.telefono as 'Teléfono', c.email as 'Email', e.descripcion as 'Estado de Socio' FROM Cliente c, TipoDNI t, EstadoSocio e WHERE c.idTipoDNI=t.idTipoDNI AND c.idEstadoSocio=e.idEstadoSocio AND c.apellidos like '%" & txtTextoABuscar.Text & "%'"
        Select Case cmbCategoria.SelectedIndex
            Case 0
                If Not mtxtNroDocumento.Text.Trim = "" Then
                    consulta += " AND t.idTipoDNI =" & cmbFiltro.SelectedValue & " AND c.nroDNI=" & mtxtNroDocumento.Text
                End If
        End Select
        'FrmABMCliente.limpiarCampos()
        Dim tabla As Data.DataTable = acceso._consulta(consulta)
        frmCliente.resultadoBusqueda(tabla)
        Me.Close()
    End Sub

    Private Sub FrmBuscarClientes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
